package com.mmall.concurrence.singleton;

import com.mmall.concurrence.annoations.Recommend;
import com.mmall.concurrence.annoations.ThreadSafe;
/**
 * 枚举模式：最安全
 *
 * @author yuelinbo
 * @date 2018/12/18 10:25
 **/
@ThreadSafe
@Recommend
public class SingletonExample5 {

    //私有构造函数
    private SingletonExample5(){

    }


    public static SingletonExample5 getInstance(){
        return Singleton.INSTANCE.getSingleton();
    }

    private enum Singleton{
        INSTANCE;
        private SingletonExample5 singleton;

        // JVM 保证这个方法绝对只调用一次
        Singleton(){
            singleton = new SingletonExample5();
        }

        public SingletonExample5 getSingleton(){
            return singleton;
        }
    }
}
